﻿using LeastSquare.model;
namespace LeastSquare
{
    /// <summary>
    /// 线性回归模型
    /// </summary>

    internal class Program
    {
        const int endyear = 2020;
        /// <summary>
        /// 最小二乘法
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //创建年份x的集合
            List<int> xlist = new List<int>();
            //将年份x存入集合中
            for (int i = 2000; i <= endyear; i++)
            {
                xlist.Add(i);
            }
            //创建GDPy的集合
            var ylist = new List<double>
            {
                1211346869600,1339395718862,1470550015077,
                1660287965663,1955347004965,2285965892364,
                2752131773358,3550342737009,4594307032667,
                5101703073088,6087163874510,7551500124197,
                8532229986993,9570406235659,10475682920597,
                11061553079871,11233276536744,12310409370894,
                13894817549380,14279937500608,14687673892882
            };
            Console.WriteLine("请输入预测年份");
            int x = Convert.ToInt32(Console.ReadLine());
            double y = Function.Method(xlist, ylist, x);
            double realY = 17734062645371;
            Console.WriteLine($"预测{x}年的GDP为{y},偏差为{(y - realY) / realY}");
            Console.ReadKey();
        }

    }

}